#Compilazione della libreria


CC = gcc
ARCH=-m64
CFLAGS = $(ARCH) -fpic -g

#folder containing the headers
INCLUDES = -I../include

#Libraries to includes
LIBS = -lconfig -lm

#define the source files, simply list all the one in the directory
SRCS=$(wildcard *.c)

# define the C object files 
#
# This uses Suffix Replacement within a macro:
#   $(name:string1=string2)
#         For each word in 'name' replace 'string1' with 'string2'
# Below we are replacing the suffix .c of all words in the macro SRCS
# with the .o suffix
#
OBJS = $(SRCS:.c=.o)

# define the executable file 
MAIN = libjjann$(ARCH)
#
# The following part of the makefile is generic; it can be used to 
# build any executable just by changing the definitions above and by
# deleting dependencies appended to the file from 'make depend'
#

.PHONY: clean

all:    $(MAIN)
	@echo  Lib Compiled

	
$(MAIN): $(OBJS) 
	#static version
	ar rcs $(MAIN).a $(OBJS)
	#compiling also the dinamic version of the library
	$(CC) $(ARCH) -fPIC -shared -o $(MAIN).so $(OBJS)
	mv $(MAIN)* ../
	mkdir -p ../obj/
	mv $(OBJS) ../obj/
	

# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file) 
# (see the gnu make manual section about automatic variables)
.c.o:
	$(CC) $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -c  $< -o $@

clean:
	$(RM) ../obj/*.o *~ ../$(MAIN) 
